import React from 'react'
import { Router, Redirect, Route, Switch } from 'react-router-dom'
import Login from '@/pages/Login'
import Layout from '@/pages/Layout'
import NotFount from '@/pages/NotFound'
// import { hasToken } from './utils/token'
import PrivaeRoute from '@/components/PrivaeRoute'
import history from './utils/histroy'
export default function App() {
  return (
    <Router history={history}>
      <div>
        {/* 重定向 */}
        <Switch>
          <Redirect exact from='/' to='/home'></Redirect>
          {/* 配置路由规则 */}
          <Route path='/login'>
            <Login></Login>
          </Route>
          {/* <Route path='/home' render={() => {
            if (hasToken()) {
              return <Layout></Layout>
            } else {
              //重定向到首页
              return <Redirect to='/login'></Redirect>
            }
          }}>

          </Route> */}
          <PrivaeRoute path='/home'>
            <Layout></Layout>
          </PrivaeRoute>
          <Route>
            <NotFount></NotFount>
          </Route>
        </Switch>
      </div>
    </Router>
  )
}
